package com.zzw;

import com.zzw.annotation.runners.CommonRunnerConfiguration;
import com.zzw.aop.MyAopAutoConfiguration;
import com.zzw.common.event.AsyncSimpleApplicationEventMulticasterConfiguration;
import com.zzw.config.CommonsServerWebMvcConfigurer;
import com.zzw.easyexcel.EasyExcelConfiguration;
import com.zzw.filters.httpfilters.HttpFilterConfiguration;
import com.zzw.filters.xssfilter.XssFilterConfiguration;
import com.zzw.futures.AsyncAutoConfiguration;
import com.zzw.golableex.GlobalExceptionConfiguration;
import com.zzw.grpc.GrpcConfiguration;
import com.zzw.interceptor.BlankInternalandlerIntereptor;
import com.zzw.interceptor.RequestContextInterceptor;
import com.zzw.jwt.JwtConfiguration;
import com.zzw.okhttp3.Okhttp3Configuration;
import com.zzw.properties.RequestContextProperties;
import com.zzw.ratelimter.RedisRateLimiterConfiguration;
import com.zzw.redisson.RedissonConfiguration;
import com.zzw.resilience4j.Res4jRateLimterConfiguration;
import com.zzw.schedule.ScheduleConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author Administrator
 */
@Configuration
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "zzw.commons.server", name = "enable", matchIfMissing = true)
@Import({CommonsServerWebMvcConfigurer.class, RedisRateLimiterConfiguration.class, Okhttp3Configuration.class, EasyExcelConfiguration.class, ScheduleConfiguration.class
        , RedissonConfiguration.class, XssFilterConfiguration.class, AsyncSimpleApplicationEventMulticasterConfiguration.class
        , AsyncAutoConfiguration.class, MyAopAutoConfiguration.class, GlobalExceptionConfiguration.class, JwtConfiguration.class
        , Res4jRateLimterConfiguration.class, HttpFilterConfiguration.class, GrpcConfiguration.class, CommonRunnerConfiguration.class
})
public class CommonsServerConfiguration {


    @Bean
    public RequestContextProperties requestContextProperties() {
        return new RequestContextProperties();
    }

    @Bean
    @ConditionalOnProperty(prefix = "zzw.simple.request.context", name = "enable")
    public RequestContextInterceptor requestContextInterceptor(RequestContextProperties requestContextProperties) {
        return new RequestContextInterceptor(requestContextProperties);
    }

    @Bean
    public BlankInternalandlerIntereptor blankInternalandlerIntereptor() {
        return new BlankInternalandlerIntereptor();
    }
}
